package com.xpgk.mvc.bloseWeight;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.ObjectUtils.Null;

import com.jfinal.log.Log;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.intoPersonnel.IntoPersonnel;

@Service(name = BloseWeightService.serviceName)
public class BloseWeightService extends  BaseService{
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(BloseWeightService.class);
	public static final String serviceName = "bloseWeightService";	
	
	/**
	 * 添加目标
	 * @param target
	 * @param targets
	 * @param curUserIds
	 * @return
	 */
	public RenderBean addTarget(DelWeiTargetSum target, List<DelWeiTarget> targets, String curUserIds){
		RenderBean result = new RenderBean();
		
		
		//加目标名称
		if(target!=null){
			//判断customerIds是否为空
			String customerIds = target.getStr(DelWeiTargetSum.column_customerIds);
			if(customerIds!=null){
			String code = target.getStr(DelWeiTargetSum.column_codeIds);
			if(code.equals("c4bb5ef9657748a59c9b2c1784f401d5") ){
				target.set(DelWeiTargetSum.column_targetName, "短期目标");
			}else if(code.equals("4180213235f540cbb9e4b13abb5a1b37")){
				target.set(DelWeiTargetSum.column_targetName, "月目标");
			}else if(code .equals("8b3c25180ca24ac9a0f02c0f45d9ff12")){
				target.set(DelWeiTargetSum.column_targetName, "月目标");
			}
			else {
				target.set(DelWeiTargetSum.column_targetName, "总目标");
			}
		
		//添加汇总表
		target.set(DelWeiTargetSum.column_createId, curUserIds).set(DelWeiTargetSum.column_createDate, new Date()).save();
		
		//添加明细表
		if(targets.size() > 0){
			for(DelWeiTarget dwt : targets){
				dwt.set(DelWeiTarget.column_targetIds, target.getPKValue()).save();
			}
		}
		result.setCode(ConstantRender.render_success_code);
			}else{
				result.setMsg("请选择顾客");;
			}
		}
		return result;
		
	}
	
	/**
	 * 修改目标
	 * @param targets
	 * @param curUserIds
	 * @return
	 */
	public RenderBean upTarget(List<DelWeiTarget> targets, String curUserIds){
		RenderBean result = new RenderBean();
		if(targets.size() > 0){
			for(DelWeiTarget dwt : targets){
				dwt.update();
			}
		}
		result.setCode(ConstantRender.render_success_code);
		return result;
	}
	
	/**
	 * 删除目标
	 * @param targets
	 * @param curUserIds
	 * @return
	 */
	public RenderBean deleteTarget(DelWeiTargetSum delWeiTargetSum){
		RenderBean result = new RenderBean();
		
		if(delWeiTargetSum!=null){
			delWeiTargetSum.set(delWeiTargetSum.column_dataStatus, "0");
		}
		if(!delWeiTargetSum.update())
		{
			log.debug("删除目标失败");
			throw new RuntimeException("删除目标失败!");
		}
		
		result.setCode(ConstantRender.render_success_code);
		return result;
	}
	

}
